﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.RenderTexture
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using UnityEngine.Bindings;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Internal;
using UnityEngine.Rendering;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>Render textures are textures that can be rendered to.</para>
  /// </summary>
  [UsedByNativeCode]
  [NativeHeader("Runtime/Camera/Camera.h")]
  [NativeHeader("Runtime/Graphics/RenderBufferManager.h")]
  [NativeHeader("Runtime/Graphics/RenderTexture.h")]
  [NativeHeader("Runtime/Graphics/GraphicsScriptBindings.h")]
  public class RenderTexture : Texture
  {
    /// <summary>
    ///   <para>The width of the render texture in pixels.</para>
    /// </summary>
    public override extern int width { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>The height of the render texture in pixels.</para>
    /// </summary>
    public override extern int height { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Dimensionality (type) of the render texture.</para>
    /// </summary>
    public override extern TextureDimension dimension { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>The color format of the render texture. You can set the color format to None to achieve depth-only rendering.</para>
    /// </summary>
    [NativeProperty("ColorFormat")]
    public new extern GraphicsFormat graphicsFormat { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Render texture has mipmaps when this flag is set.</para>
    /// </summary>
    [NativeProperty("MipMap")]
    public extern bool useMipMap { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Does this render texture use sRGB read/write conversions? (Read Only).</para>
    /// </summary>
    [NativeProperty("SRGBReadWrite")]
    public extern bool sRGB { [MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>If this RenderTexture is a VR eye texture used in stereoscopic rendering, this property decides what special rendering occurs, if any.</para>
    /// </summary>
    [NativeProperty("VRUsage")]
    public extern VRTextureUsage vrUsage { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>The render texture memoryless mode property.</para>
    /// </summary>
    [NativeProperty("Memoryless")]
    public extern RenderTextureMemoryless memorylessMode { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    public RenderTextureFormat format
    {
      get
      {
        return this.graphicsFormat != 0 ? GraphicsFormatUtility.GetRenderTextureFormat(this.graphicsFormat) : (this.GetDescriptor().shadowSamplingMode != ShadowSamplingMode.None ? RenderTextureFormat.Shadowmap : RenderTextureFormat.Depth);
      }
      set => this.graphicsFormat = GraphicsFormatUtility.GetGraphicsFormat(value, this.sRGB);
    }

    /// <summary>
    ///         <para>The format of the stencil data that you can encapsulate within a RenderTexture.
    /// 
    /// Specifying this property creates a stencil element for the RenderTexture and sets its format.
    /// This allows for stencil data to be bound as a Texture to all shader types for the platforms that support it.
    /// This property does not specify the format of the stencil buffer, which is constrained by the depth buffer format specified in RenderTexture.depth.
    /// 
    /// Currently, most platforms only support R8_UInt (DirectX11, DirectX12), while PS4 also supports R8_UNorm.</para>
    ///       </summary>
    public extern GraphicsFormat stencilFormat { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>The format of the depth/stencil buffer.</para>
    /// </summary>
    public extern GraphicsFormat depthStencilFormat { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Mipmap levels are generated automatically when this flag is set.</para>
    /// </summary>
    public extern bool autoGenerateMips { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Volume extent of a 3D render texture or number of slices of array texture.</para>
    /// </summary>
    public extern int volumeDepth { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>The antialiasing level for the RenderTexture.</para>
    /// </summary>
    public extern int antiAliasing { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>If true and antiAliasing is greater than 1, the render texture will not be resolved by default.  Use this if the render texture needs to be bound as a multisampled texture in a shader.</para>
    /// </summary>
    public extern bool bindTextureMS { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Enable random access write into this render texture on Shader Model 5.0 level shaders.</para>
    /// </summary>
    public extern bool enableRandomWrite { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Is the render texture marked to be scaled by the.</para>
    /// </summary>
    public extern bool useDynamicScale { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern bool GetIsPowerOfTwo();

    public bool isPowerOfTwo
    {
      get => this.GetIsPowerOfTwo();
      set
      {
      }
    }

    [FreeFunction("RenderTexture::GetActive")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern RenderTexture GetActive();

    [FreeFunction("RenderTextureScripting::SetActive")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void SetActive(RenderTexture rt);

    /// <summary>
    ///   <para>Currently active render texture.</para>
    /// </summary>
    public static RenderTexture active
    {
      get => RenderTexture.GetActive();
      set => RenderTexture.SetActive(value);
    }

    [FreeFunction(Name = "RenderTextureScripting::GetColorBuffer", HasExplicitThis = true)]
    private RenderBuffer GetColorBuffer()
    {
      RenderBuffer ret;
      this.GetColorBuffer_Injected(out ret);
      return ret;
    }

    [FreeFunction(Name = "RenderTextureScripting::GetDepthBuffer", HasExplicitThis = true)]
    private RenderBuffer GetDepthBuffer()
    {
      RenderBuffer ret;
      this.GetDepthBuffer_Injected(out ret);
      return ret;
    }

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void SetMipMapCount(int count);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void SetShadowSamplingMode(ShadowSamplingMode samplingMode);

    /// <summary>
    ///   <para>Color buffer of the render texture (Read Only).</para>
    /// </summary>
    public RenderBuffer colorBuffer => this.GetColorBuffer();

    /// <summary>
    ///   <para>Depth/stencil buffer of the render texture (Read Only).</para>
    /// </summary>
    public RenderBuffer depthBuffer => this.GetDepthBuffer();

    /// <summary>
    ///   <para>Retrieve a native (underlying graphics API) pointer to the depth buffer resource.</para>
    /// </summary>
    /// <returns>
    ///   <para>Pointer to an underlying graphics API depth buffer resource.</para>
    /// </returns>
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern IntPtr GetNativeDepthBufferPtr();

    /// <summary>
    ///   <para>Hint the GPU driver that the contents of the RenderTexture will not be used.</para>
    /// </summary>
    /// <param name="discardColor">Should the colour buffer be discarded?</param>
    /// <param name="discardDepth">Should the depth buffer be discarded?</param>
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern void DiscardContents(bool discardColor, bool discardDepth);

    /// <summary>
    ///   <para>Indicate that there's a RenderTexture restore operation expected.</para>
    /// </summary>
    [Obsolete("This function has no effect.", false)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern void MarkRestoreExpected();

    /// <summary>
    ///   <para>Hint the GPU driver that the contents of the RenderTexture will not be used.</para>
    /// </summary>
    /// <param name="discardColor">Should the colour buffer be discarded?</param>
    /// <param name="discardDepth">Should the depth buffer be discarded?</param>
    public void DiscardContents() => this.DiscardContents(true, true);

    [NativeName("ResolveAntiAliasedSurface")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void ResolveAA();

    [NativeName("ResolveAntiAliasedSurface")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void ResolveAATo(RenderTexture rt);

    /// <summary>
    ///   <para>Force an antialiased render texture to be resolved.</para>
    /// </summary>
    /// <param name="target">The render texture to resolve into.  If set, the target render texture must have the same dimensions and format as the source.</param>
    public void ResolveAntiAliasedSurface() => this.ResolveAA();

    /// <summary>
    ///   <para>Force an antialiased render texture to be resolved.</para>
    /// </summary>
    /// <param name="target">The render texture to resolve into.  If set, the target render texture must have the same dimensions and format as the source.</param>
    public void ResolveAntiAliasedSurface(RenderTexture target) => this.ResolveAATo(target);

    /// <summary>
    ///   <para>Assigns this RenderTexture as a global shader property named propertyName.</para>
    /// </summary>
    /// <param name="propertyName"></param>
    [FreeFunction(Name = "RenderTextureScripting::SetGlobalShaderProperty", HasExplicitThis = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern void SetGlobalShaderProperty(string propertyName);

    /// <summary>
    ///   <para>Actually creates the RenderTexture.</para>
    /// </summary>
    /// <returns>
    ///   <para>True if the texture is created, else false.</para>
    /// </returns>
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern bool Create();

    /// <summary>
    ///   <para>Releases the RenderTexture.</para>
    /// </summary>
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern void Release();

    /// <summary>
    ///   <para>Is the render texture actually created?</para>
    /// </summary>
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern bool IsCreated();

    /// <summary>
    ///   <para>Generate mipmap levels of a render texture.</para>
    /// </summary>
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern void GenerateMips();

    [NativeThrows]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern void ConvertToEquirect(RenderTexture equirect, Camera.MonoOrStereoscopicEye eye = Camera.MonoOrStereoscopicEye.Mono);

    [MethodImpl(MethodImplOptions.InternalCall)]
    internal extern void SetSRGBReadWrite(bool srgb);

    [FreeFunction("RenderTextureScripting::Create")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void Internal_Create([Writable] RenderTexture rt);

    /// <summary>
    ///   <para>Does a RenderTexture have stencil buffer?</para>
    /// </summary>
    /// <param name="rt">Render texture, or null for main screen.</param>
    [FreeFunction("RenderTextureSupportsStencil")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern bool SupportsStencil(RenderTexture rt);

    [NativeName("SetRenderTextureDescFromScript")]
    private void SetRenderTextureDescriptor(RenderTextureDescriptor desc)
    {
      this.SetRenderTextureDescriptor_Injected(ref desc);
    }

    [NativeName("GetRenderTextureDesc")]
    private RenderTextureDescriptor GetDescriptor()
    {
      RenderTextureDescriptor ret;
      this.GetDescriptor_Injected(out ret);
      return ret;
    }

    [FreeFunction("GetRenderBufferManager().GetTextures().GetTempBuffer")]
    private static RenderTexture GetTemporary_Internal(RenderTextureDescriptor desc)
    {
      return RenderTexture.GetTemporary_Internal_Injected(ref desc);
    }

    /// <summary>
    ///   <para>Release a temporary texture allocated with GetTemporary.</para>
    /// </summary>
    /// <param name="temp"></param>
    [FreeFunction("GetRenderBufferManager().GetTextures().ReleaseTempBuffer")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern void ReleaseTemporary(RenderTexture temp);

    /// <summary>
    ///   <para>The precision of the render texture's depth buffer in bits (0, 16, 24 and 32 are supported).</para>
    /// </summary>
    public extern int depth { [FreeFunction("RenderTextureScripting::GetDepth", HasExplicitThis = true), MethodImpl(MethodImplOptions.InternalCall)] get; [FreeFunction("RenderTextureScripting::SetDepth", HasExplicitThis = true), MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Creates a new RenderTexture object.</para>
    /// </summary>
    /// <param name="width">Texture width in pixels.</param>
    /// <param name="height">Texture height in pixels.</param>
    /// <param name="depth">Number of bits in depth buffer (0, 16, 24 or 32). Note that only 24 and 32 bit depth have stencil buffer support.</param>
    /// <param name="format">Texture color format.</param>
    /// <param name="colorFormat">The color format for the RenderTexture.</param>
    /// <param name="depthStencilFormat">The depth stencil format for the RenderTexture.</param>
    /// <param name="mipCount">Amount of mips to allocate for the RenderTexture.</param>
    /// <param name="readWrite">How color space conversions are applied on texture read/write.</param>
    /// <param name="desc">Create the RenderTexture with the settings in the RenderTextureDescriptor.</param>
    /// <param name="textureToCopy">Copy the settings from another RenderTexture.</param>
    [RequiredByNativeCode]
    protected internal RenderTexture()
    {
    }

    /// <summary>
    ///   <para>Creates a new RenderTexture object.</para>
    /// </summary>
    /// <param name="width">Texture width in pixels.</param>
    /// <param name="height">Texture height in pixels.</param>
    /// <param name="depth">Number of bits in depth buffer (0, 16, 24 or 32). Note that only 24 and 32 bit depth have stencil buffer support.</param>
    /// <param name="format">Texture color format.</param>
    /// <param name="colorFormat">The color format for the RenderTexture.</param>
    /// <param name="depthStencilFormat">The depth stencil format for the RenderTexture.</param>
    /// <param name="mipCount">Amount of mips to allocate for the RenderTexture.</param>
    /// <param name="readWrite">How color space conversions are applied on texture read/write.</param>
    /// <param name="desc">Create the RenderTexture with the settings in the RenderTextureDescriptor.</param>
    /// <param name="textureToCopy">Copy the settings from another RenderTexture.</param>
    public RenderTexture(RenderTextureDescriptor desc)
    {
      RenderTexture.ValidateRenderTextureDesc(desc);
      RenderTexture.Internal_Create(this);
      this.SetRenderTextureDescriptor(desc);
    }

    /// <summary>
    ///   <para>Creates a new RenderTexture object.</para>
    /// </summary>
    /// <param name="width">Texture width in pixels.</param>
    /// <param name="height">Texture height in pixels.</param>
    /// <param name="depth">Number of bits in depth buffer (0, 16, 24 or 32). Note that only 24 and 32 bit depth have stencil buffer support.</param>
    /// <param name="format">Texture color format.</param>
    /// <param name="colorFormat">The color format for the RenderTexture.</param>
    /// <param name="depthStencilFormat">The depth stencil format for the RenderTexture.</param>
    /// <param name="mipCount">Amount of mips to allocate for the RenderTexture.</param>
    /// <param name="readWrite">How color space conversions are applied on texture read/write.</param>
    /// <param name="desc">Create the RenderTexture with the settings in the RenderTextureDescriptor.</param>
    /// <param name="textureToCopy">Copy the settings from another RenderTexture.</param>
    public RenderTexture(RenderTexture textureToCopy)
    {
      if ((Object) textureToCopy == (Object) null)
        throw new ArgumentNullException(nameof (textureToCopy));
      RenderTexture.ValidateRenderTextureDesc(textureToCopy.descriptor);
      RenderTexture.Internal_Create(this);
      this.SetRenderTextureDescriptor(textureToCopy.descriptor);
    }

    [ExcludeFromDocs]
    public RenderTexture(int width, int height, int depth, DefaultFormat format)
      : this(width, height, RenderTexture.GetDefaultColorFormat(format), RenderTexture.GetDefaultDepthStencilFormat(format, depth), Texture.GenerateAllMips)
    {
    }

    [ExcludeFromDocs]
    public RenderTexture(int width, int height, int depth, GraphicsFormat format)
      : this(width, height, depth, format, Texture.GenerateAllMips)
    {
    }

    [ExcludeFromDocs]
    public RenderTexture(int width, int height, int depth, GraphicsFormat format, int mipCount)
    {
      if (format != GraphicsFormat.None && !this.ValidateFormat(format, FormatUsage.Render))
        return;
      RenderTexture.Internal_Create(this);
      this.depthStencilFormat = RenderTexture.GetDepthStencilFormatLegacy(depth, format);
      this.width = width;
      this.height = height;
      this.graphicsFormat = format;
      this.SetMipMapCount(mipCount);
      this.SetSRGBReadWrite(GraphicsFormatUtility.IsSRGBFormat(format));
    }

    [ExcludeFromDocs]
    public RenderTexture(
      int width,
      int height,
      GraphicsFormat colorFormat,
      GraphicsFormat depthStencilFormat,
      int mipCount)
    {
      if (colorFormat != GraphicsFormat.None && !this.ValidateFormat(colorFormat, FormatUsage.Render))
        return;
      RenderTexture.Internal_Create(this);
      this.width = width;
      this.height = height;
      this.depthStencilFormat = depthStencilFormat;
      this.graphicsFormat = colorFormat;
      this.SetMipMapCount(mipCount);
      this.SetSRGBReadWrite(GraphicsFormatUtility.IsSRGBFormat(colorFormat));
    }

    [ExcludeFromDocs]
    public RenderTexture(
      int width,
      int height,
      GraphicsFormat colorFormat,
      GraphicsFormat depthStencilFormat)
      : this(width, height, colorFormat, depthStencilFormat, Texture.GenerateAllMips)
    {
    }

    /// <summary>
    ///   <para>Creates a new RenderTexture object.</para>
    /// </summary>
    /// <param name="width">Texture width in pixels.</param>
    /// <param name="height">Texture height in pixels.</param>
    /// <param name="depth">Number of bits in depth buffer (0, 16, 24 or 32). Note that only 24 and 32 bit depth have stencil buffer support.</param>
    /// <param name="format">Texture color format.</param>
    /// <param name="colorFormat">The color format for the RenderTexture.</param>
    /// <param name="depthStencilFormat">The depth stencil format for the RenderTexture.</param>
    /// <param name="mipCount">Amount of mips to allocate for the RenderTexture.</param>
    /// <param name="readWrite">How color space conversions are applied on texture read/write.</param>
    /// <param name="desc">Create the RenderTexture with the settings in the RenderTextureDescriptor.</param>
    /// <param name="textureToCopy">Copy the settings from another RenderTexture.</param>
    public RenderTexture(
      int width,
      int height,
      int depth,
      [UnityEngine.Internal.DefaultValue("RenderTextureFormat.Default")] RenderTextureFormat format,
      [UnityEngine.Internal.DefaultValue("RenderTextureReadWrite.Default")] RenderTextureReadWrite readWrite)
    {
      this.Initialize(width, height, depth, format, readWrite, Texture.GenerateAllMips);
    }

    /// <summary>
    ///   <para>Creates a new RenderTexture object.</para>
    /// </summary>
    /// <param name="width">Texture width in pixels.</param>
    /// <param name="height">Texture height in pixels.</param>
    /// <param name="depth">Number of bits in depth buffer (0, 16, 24 or 32). Note that only 24 and 32 bit depth have stencil buffer support.</param>
    /// <param name="format">Texture color format.</param>
    /// <param name="colorFormat">The color format for the RenderTexture.</param>
    /// <param name="depthStencilFormat">The depth stencil format for the RenderTexture.</param>
    /// <param name="mipCount">Amount of mips to allocate for the RenderTexture.</param>
    /// <param name="readWrite">How color space conversions are applied on texture read/write.</param>
    /// <param name="desc">Create the RenderTexture with the settings in the RenderTextureDescriptor.</param>
    /// <param name="textureToCopy">Copy the settings from another RenderTexture.</param>
    [ExcludeFromDocs]
    public RenderTexture(int width, int height, int depth, RenderTextureFormat format)
      : this(width, height, depth, format, Texture.GenerateAllMips)
    {
    }

    /// <summary>
    ///   <para>Creates a new RenderTexture object.</para>
    /// </summary>
    /// <param name="width">Texture width in pixels.</param>
    /// <param name="height">Texture height in pixels.</param>
    /// <param name="depth">Number of bits in depth buffer (0, 16, 24 or 32). Note that only 24 and 32 bit depth have stencil buffer support.</param>
    /// <param name="format">Texture color format.</param>
    /// <param name="colorFormat">The color format for the RenderTexture.</param>
    /// <param name="depthStencilFormat">The depth stencil format for the RenderTexture.</param>
    /// <param name="mipCount">Amount of mips to allocate for the RenderTexture.</param>
    /// <param name="readWrite">How color space conversions are applied on texture read/write.</param>
    /// <param name="desc">Create the RenderTexture with the settings in the RenderTextureDescriptor.</param>
    /// <param name="textureToCopy">Copy the settings from another RenderTexture.</param>
    [ExcludeFromDocs]
    public RenderTexture(int width, int height, int depth)
      : this(width, height, depth, RenderTextureFormat.Default)
    {
    }

    [ExcludeFromDocs]
    public RenderTexture(
      int width,
      int height,
      int depth,
      RenderTextureFormat format,
      int mipCount)
    {
      this.Initialize(width, height, depth, format, RenderTextureReadWrite.Default, mipCount);
    }

    private void Initialize(
      int width,
      int height,
      int depth,
      RenderTextureFormat format,
      RenderTextureReadWrite readWrite,
      int mipCount)
    {
      GraphicsFormat compatibleFormat = RenderTexture.GetCompatibleFormat(format, readWrite);
      GraphicsFormat stencilFormatLegacy = RenderTexture.GetDepthStencilFormatLegacy(depth, format);
      if (compatibleFormat != 0 && !this.ValidateFormat(compatibleFormat, FormatUsage.Render))
        return;
      RenderTexture.Internal_Create(this);
      this.width = width;
      this.height = height;
      this.depthStencilFormat = stencilFormatLegacy;
      this.graphicsFormat = compatibleFormat;
      this.SetMipMapCount(mipCount);
      this.SetSRGBReadWrite(GraphicsFormatUtility.IsSRGBFormat(compatibleFormat));
    }

    internal static GraphicsFormat GetDepthStencilFormatLegacy(
      int depthBits,
      GraphicsFormat colorFormat)
    {
      return colorFormat == GraphicsFormat.ShadowAuto ? GraphicsFormatUtility.GetDepthStencilFormat(depthBits, 0) : GraphicsFormatUtility.GetDepthStencilFormat(depthBits);
    }

    internal static GraphicsFormat GetDepthStencilFormatLegacy(
      int depthBits,
      RenderTextureFormat format)
    {
      return RenderTexture.GetDepthStencilFormatLegacy(depthBits, format == RenderTextureFormat.Shadowmap);
    }

    internal static GraphicsFormat GetDepthStencilFormatLegacy(int depthBits, DefaultFormat format)
    {
      return RenderTexture.GetDepthStencilFormatLegacy(depthBits, format == DefaultFormat.Shadow);
    }

    internal static GraphicsFormat GetDepthStencilFormatLegacy(
      int depthBits,
      bool requestedShadowMap)
    {
      return requestedShadowMap ? GraphicsFormatUtility.GetDepthStencilFormat(depthBits, 0) : GraphicsFormatUtility.GetDepthStencilFormat(depthBits);
    }

    /// <summary>
    ///   <para>This struct contains all the information required to create a RenderTexture. It can be copied, cached, and reused to easily create RenderTextures that all share the same properties.</para>
    /// </summary>
    public RenderTextureDescriptor descriptor
    {
      get => this.GetDescriptor();
      set
      {
        RenderTexture.ValidateRenderTextureDesc(value);
        this.SetRenderTextureDescriptor(value);
      }
    }

    private static void ValidateRenderTextureDesc(RenderTextureDescriptor desc)
    {
      if (desc.graphicsFormat == GraphicsFormat.None && desc.depthStencilFormat == GraphicsFormat.None)
        throw new ArgumentException("RenderTextureDesc graphicsFormat and depthStencilFormat cannot both be None.");
      if (desc.graphicsFormat != GraphicsFormat.None && !SystemInfo.IsFormatSupported(desc.graphicsFormat, FormatUsage.Render))
        throw new ArgumentException("RenderTextureDesc graphicsFormat must be a supported GraphicsFormat. " + desc.graphicsFormat.ToString() + " is not supported on this platform.", "desc.graphicsFormat");
      if (desc.depthStencilFormat != GraphicsFormat.None && !GraphicsFormatUtility.IsDepthFormat(desc.depthStencilFormat) && !GraphicsFormatUtility.IsStencilFormat(desc.depthStencilFormat))
        throw new ArgumentException("RenderTextureDesc depthStencilFormat must be a supported depth/stencil GraphicsFormat. " + desc.depthStencilFormat.ToString() + " is not supported on this platform.", "desc.depthStencilFormat");
      if (desc.width <= 0)
        throw new ArgumentException("RenderTextureDesc width must be greater than zero.", "desc.width");
      if (desc.height <= 0)
        throw new ArgumentException("RenderTextureDesc height must be greater than zero.", "desc.height");
      if (desc.volumeDepth <= 0)
        throw new ArgumentException("RenderTextureDesc volumeDepth must be greater than zero.", "desc.volumeDepth");
      if (desc.msaaSamples != 1 && desc.msaaSamples != 2 && desc.msaaSamples != 4 && desc.msaaSamples != 8)
        throw new ArgumentException("RenderTextureDesc msaaSamples must be 1, 2, 4, or 8.", "desc.msaaSamples");
      if (desc.dimension == TextureDimension.CubeArray && desc.volumeDepth % 6 != 0)
        throw new ArgumentException("RenderTextureDesc volumeDepth must be a multiple of 6 when dimension is CubeArray", "desc.volumeDepth");
      if (desc.graphicsFormat != GraphicsFormat.ShadowAuto && desc.graphicsFormat != GraphicsFormat.DepthAuto && (GraphicsFormatUtility.IsDepthFormat(desc.graphicsFormat) || GraphicsFormatUtility.IsStencilFormat(desc.graphicsFormat)))
        throw new ArgumentException("RenderTextureDesc graphicsFormat must not be a depth/stencil format. " + desc.graphicsFormat.ToString() + " is not supported.", "desc.graphicsFormat");
    }

    internal static GraphicsFormat GetDefaultColorFormat(DefaultFormat format)
    {
      switch (format)
      {
        case DefaultFormat.DepthStencil:
          return GraphicsFormat.DepthAuto;
        case DefaultFormat.Shadow:
          return GraphicsFormat.ShadowAuto;
        default:
          return SystemInfo.GetGraphicsFormat(format);
      }
    }

    internal static GraphicsFormat GetDefaultDepthStencilFormat(DefaultFormat format, int depth)
    {
      switch (format)
      {
        case DefaultFormat.DepthStencil:
        case DefaultFormat.Shadow:
          return SystemInfo.GetGraphicsFormat(format);
        default:
          return RenderTexture.GetDepthStencilFormatLegacy(depth, format);
      }
    }

    internal static GraphicsFormat GetCompatibleFormat(
      RenderTextureFormat renderTextureFormat,
      RenderTextureReadWrite readWrite)
    {
      GraphicsFormat graphicsFormat = GraphicsFormatUtility.GetGraphicsFormat(renderTextureFormat, readWrite);
      GraphicsFormat compatibleFormat = SystemInfo.GetCompatibleFormat(graphicsFormat, FormatUsage.Render);
      if (graphicsFormat == compatibleFormat)
        return graphicsFormat;
      Debug.LogWarning((object) string.Format("'{0}' is not supported. RenderTexture::GetTemporary fallbacks to {1} format on this platform. Use 'SystemInfo.IsFormatSupported' C# API to check format support.", (object) graphicsFormat.ToString(), (object) compatibleFormat.ToString()));
      return compatibleFormat;
    }

    /// <summary>
    ///   <para>Allocate a temporary render texture.</para>
    /// </summary>
    /// <param name="width">Width in pixels.</param>
    /// <param name="height">Height in pixels.</param>
    /// <param name="depthBuffer">Depth buffer bits (0, 16 or 24). Note that only 24 bit depth has stencil buffer.</param>
    /// <param name="format">Render texture format.</param>
    /// <param name="readWrite">Color space conversion mode.</param>
    /// <param name="antiAliasing">Number of antialiasing samples to store in the texture. Valid values are 1, 2, 4, and 8. Throws an exception if any other value is passed.</param>
    /// <param name="memorylessMode">Render texture memoryless mode.</param>
    /// <param name="vrUsage">How Unity uses the RenderTexture as a VR eye texture. The default is VRTextureUsage.None.</param>
    /// <param name="useDynamicScale">Determines whether Unity scales the render texture using. The default is false.</param>
    /// <param name="desc">Use this RenderTextureDesc for the settings when creating the temporary RenderTexture.</param>
    public static RenderTexture GetTemporary(RenderTextureDescriptor desc)
    {
      RenderTexture.ValidateRenderTextureDesc(desc);
      desc.createdFromScript = true;
      return RenderTexture.GetTemporary_Internal(desc);
    }

    private static RenderTexture GetTemporaryImpl(
      int width,
      int height,
      GraphicsFormat depthStencilFormat,
      GraphicsFormat colorFormat,
      int antiAliasing = 1,
      RenderTextureMemoryless memorylessMode = RenderTextureMemoryless.None,
      VRTextureUsage vrUsage = VRTextureUsage.None,
      bool useDynamicScale = false)
    {
      return RenderTexture.GetTemporary(new RenderTextureDescriptor(width, height, colorFormat, depthStencilFormat)
      {
        msaaSamples = antiAliasing,
        memoryless = memorylessMode,
        vrUsage = vrUsage,
        useDynamicScale = useDynamicScale
      });
    }

    [ExcludeFromDocs]
    public static RenderTexture GetTemporary(
      int width,
      int height,
      int depthBuffer,
      GraphicsFormat format,
      [UnityEngine.Internal.DefaultValue("1")] int antiAliasing,
      [UnityEngine.Internal.DefaultValue("RenderTextureMemoryless.None")] RenderTextureMemoryless memorylessMode,
      [UnityEngine.Internal.DefaultValue("VRTextureUsage.None")] VRTextureUsage vrUsage,
      [UnityEngine.Internal.DefaultValue("false")] bool useDynamicScale)
    {
      return RenderTexture.GetTemporaryImpl(width, height, RenderTexture.GetDepthStencilFormatLegacy(depthBuffer, format), format, antiAliasing, memorylessMode, vrUsage, useDynamicScale);
    }

    [ExcludeFromDocs]
    public static RenderTexture GetTemporary(
      int width,
      int height,
      int depthBuffer,
      GraphicsFormat format,
      int antiAliasing,
      RenderTextureMemoryless memorylessMode,
      VRTextureUsage vrUsage)
    {
      return RenderTexture.GetTemporary(width, height, depthBuffer, format, antiAliasing, memorylessMode, vrUsage, false);
    }

    [ExcludeFromDocs]
    public static RenderTexture GetTemporary(
      int width,
      int height,
      int depthBuffer,
      GraphicsFormat format,
      int antiAliasing,
      RenderTextureMemoryless memorylessMode)
    {
      return RenderTexture.GetTemporary(width, height, depthBuffer, format, antiAliasing, memorylessMode, VRTextureUsage.None);
    }

    [ExcludeFromDocs]
    public static RenderTexture GetTemporary(
      int width,
      int height,
      int depthBuffer,
      GraphicsFormat format,
      int antiAliasing)
    {
      return RenderTexture.GetTemporary(width, height, depthBuffer, format, antiAliasing, RenderTextureMemoryless.None);
    }

    [ExcludeFromDocs]
    public static RenderTexture GetTemporary(
      int width,
      int height,
      int depthBuffer,
      GraphicsFormat format)
    {
      return RenderTexture.GetTemporary(width, height, depthBuffer, format, 1);
    }

    /// <summary>
    ///   <para>Allocate a temporary render texture.</para>
    /// </summary>
    /// <param name="width">Width in pixels.</param>
    /// <param name="height">Height in pixels.</param>
    /// <param name="depthBuffer">Depth buffer bits (0, 16 or 24). Note that only 24 bit depth has stencil buffer.</param>
    /// <param name="format">Render texture format.</param>
    /// <param name="readWrite">Color space conversion mode.</param>
    /// <param name="antiAliasing">Number of antialiasing samples to store in the texture. Valid values are 1, 2, 4, and 8. Throws an exception if any other value is passed.</param>
    /// <param name="memorylessMode">Render texture memoryless mode.</param>
    /// <param name="vrUsage">How Unity uses the RenderTexture as a VR eye texture. The default is VRTextureUsage.None.</param>
    /// <param name="useDynamicScale">Determines whether Unity scales the render texture using. The default is false.</param>
    /// <param name="desc">Use this RenderTextureDesc for the settings when creating the temporary RenderTexture.</param>
    public static RenderTexture GetTemporary(
      int width,
      int height,
      [UnityEngine.Internal.DefaultValue("0")] int depthBuffer,
      [UnityEngine.Internal.DefaultValue("RenderTextureFormat.Default")] RenderTextureFormat format,
      [UnityEngine.Internal.DefaultValue("RenderTextureReadWrite.Default")] RenderTextureReadWrite readWrite,
      [UnityEngine.Internal.DefaultValue("1")] int antiAliasing,
      [UnityEngine.Internal.DefaultValue("RenderTextureMemoryless.None")] RenderTextureMemoryless memorylessMode,
      [UnityEngine.Internal.DefaultValue("VRTextureUsage.None")] VRTextureUsage vrUsage,
      [UnityEngine.Internal.DefaultValue("false")] bool useDynamicScale)
    {
      GraphicsFormat compatibleFormat = RenderTexture.GetCompatibleFormat(format, readWrite);
      GraphicsFormat stencilFormatLegacy = RenderTexture.GetDepthStencilFormatLegacy(depthBuffer, format);
      return RenderTexture.GetTemporaryImpl(width, height, stencilFormatLegacy, compatibleFormat, antiAliasing, memorylessMode, vrUsage, useDynamicScale);
    }

    [ExcludeFromDocs]
    public static RenderTexture GetTemporary(
      int width,
      int height,
      int depthBuffer,
      RenderTextureFormat format,
      RenderTextureReadWrite readWrite,
      int antiAliasing,
      RenderTextureMemoryless memorylessMode,
      VRTextureUsage vrUsage)
    {
      return RenderTexture.GetTemporary(width, height, depthBuffer, format, readWrite, antiAliasing, memorylessMode, vrUsage, false);
    }

    [ExcludeFromDocs]
    public static RenderTexture GetTemporary(
      int width,
      int height,
      int depthBuffer,
      RenderTextureFormat format,
      RenderTextureReadWrite readWrite,
      int antiAliasing,
      RenderTextureMemoryless memorylessMode)
    {
      return RenderTexture.GetTemporary(width, height, depthBuffer, format, readWrite, antiAliasing, memorylessMode, VRTextureUsage.None);
    }

    [ExcludeFromDocs]
    public static RenderTexture GetTemporary(
      int width,
      int height,
      int depthBuffer,
      RenderTextureFormat format,
      RenderTextureReadWrite readWrite,
      int antiAliasing)
    {
      return RenderTexture.GetTemporary(width, height, depthBuffer, format, readWrite, antiAliasing, RenderTextureMemoryless.None);
    }

    [ExcludeFromDocs]
    public static RenderTexture GetTemporary(
      int width,
      int height,
      int depthBuffer,
      RenderTextureFormat format,
      RenderTextureReadWrite readWrite)
    {
      return RenderTexture.GetTemporary(width, height, depthBuffer, format, readWrite, 1);
    }

    [ExcludeFromDocs]
    public static RenderTexture GetTemporary(
      int width,
      int height,
      int depthBuffer,
      RenderTextureFormat format)
    {
      return RenderTexture.GetTemporary(width, height, depthBuffer, format, RenderTextureReadWrite.Default);
    }

    [ExcludeFromDocs]
    public static RenderTexture GetTemporary(int width, int height, int depthBuffer)
    {
      return RenderTexture.GetTemporary(width, height, depthBuffer, RenderTextureFormat.Default);
    }

    [ExcludeFromDocs]
    public static RenderTexture GetTemporary(int width, int height)
    {
      return RenderTexture.GetTemporary(width, height, 0);
    }

    [Obsolete("Use RenderTexture.autoGenerateMips instead (UnityUpgradable) -> autoGenerateMips", false)]
    [EditorBrowsable(EditorBrowsableState.Never)]
    public bool generateMips
    {
      get => this.autoGenerateMips;
      set => this.autoGenerateMips = value;
    }

    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("UsSetBorderColor is no longer supported.", true)]
    public void SetBorderColor(Color color)
    {
    }

    [Obsolete("Use RenderTexture.dimension instead.", false)]
    public bool isCubemap
    {
      get => this.dimension == TextureDimension.Cube;
      set => this.dimension = value ? TextureDimension.Cube : TextureDimension.Tex2D;
    }

    /// <summary>
    ///   <para>If enabled, this Render Texture will be used as a Texture3D.</para>
    /// </summary>
    [Obsolete("Use RenderTexture.dimension instead.", false)]
    public bool isVolume
    {
      get => this.dimension == TextureDimension.Tex3D;
      set => this.dimension = value ? TextureDimension.Tex3D : TextureDimension.Tex2D;
    }

    [Obsolete("RenderTexture.enabled is always now, no need to use it.", false)]
    [EditorBrowsable(EditorBrowsableState.Never)]
    public static bool enabled
    {
      get => true;
      set
      {
      }
    }

    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("GetTexelOffset always returns zero now, no point in using it.", false)]
    public Vector2 GetTexelOffset() => Vector2.zero;

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void GetColorBuffer_Injected(out RenderBuffer ret);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void GetDepthBuffer_Injected(out RenderBuffer ret);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void SetRenderTextureDescriptor_Injected(ref RenderTextureDescriptor desc);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void GetDescriptor_Injected(out RenderTextureDescriptor ret);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern RenderTexture GetTemporary_Internal_Injected(
      ref RenderTextureDescriptor desc);
  }
}
